package customer.zspt.cn.customer.components.chat.ChatOrderContent.OrderElementPg;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.NumberPicker;
import android.widget.TextView;

import customer.zspt.cn.customer.R;
import customer.zspt.cn.customer.utils.TimestampToBj;

/**
 * Created by Administrator on 2018/9/4 0004.
 */

public class TimeADateView extends LinearLayout implements OnClickListener {
    private LinearLayout start_ll;
    private TextView time_Start;
    private LinearLayout choose_timeAdate;
    private NumberPicker date_0;
    private NumberPicker date_1;
    private NumberPicker date_2;
    private NumberPicker date_3;
    private NumberPicker date_4;
    private String Nowtime;
    public TimeADateView(Context context) {
        super(context);
        View.inflate(context, R.layout.timeanddate_item, this);
        start_ll = (LinearLayout) findViewById(R.id.start_ll);
        time_Start = (TextView) findViewById(R.id.time_Start);
        start_ll.setOnClickListener(this);

    }
    @Override
    public void onClick(View v) {
        showDialog(getContext(), time_Start);
    }
    private void showDialog(Context context, final TextView contentTv) {
        AlertDialog.Builder dialog = new AlertDialog.Builder(context);
        dialog.setTitle("请选择时间");
        View view = View.inflate(context,
                R.layout.timeanddate_dialog_item, null);
        initNumberChoose(view);
        dialog.setView(view);
        dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                int dateY = date_0.getValue();
                int dateM = date_1.getValue();
                int dateD = date_2.getValue();
                int dateH = date_3.getValue();
                int datem = date_4.getValue();
                String time = dateY+"-"+dateM+"-"+dateD+" "+dateH+":"+datem;
                contentTv.setText(time);
            }
        });
        dialog.setNegativeButton("取消", null);
        dialog.show();
    }
    private void initNumberChoose(View view) {
        Nowtime = TimestampToBj.getTimeADate(System.currentTimeMillis());
        date_0 = (NumberPicker) view.findViewById(R.id.date_0);
        date_1 = (NumberPicker) view.findViewById(R.id.date_1);
        date_2 = (NumberPicker) view.findViewById(R.id.date_2);
        date_3 = (NumberPicker) view.findViewById(R.id.date_3);
        date_4 = (NumberPicker) view.findViewById(R.id.date_4);
        String[] split = Nowtime.toString().split("-");
        date_0.setValue(Integer.parseInt(split[0]));
        date_1.setValue(Integer.parseInt(split[1]));
        date_2.setValue(Integer.parseInt(split[2]));
        date_3.setValue(Integer.parseInt(split[3]));
        date_4.setValue(Integer.parseInt(split[4]));

    }
}
